//
// Created by YxMin on 2024/7/5.
//
#ifndef GAME_NETDATA_H
#define GAME_NETDATA_H
#include <network.h>
struct GamePack{
    int packId;
    int playerId;
    int tick;
    const char *data;
    int dataLength;
};
bool ParseIpFromRoomButtonText(char* btnText, char* dest);
void ParseAndHandleRoomPackFromServer(const char* recBuffer);
void ParseAndHandleRoomPackFromClient(ClientMessage* msg);
void ParseAndHandleGamePackFromServer(const char* recBuffer);
void ParseAndHandleGamePackFromPlayer(ClientMessage* msg);
void OnPlayerQuit(int id);
void OnDisconnectServer();
//server
bool SendPlayerIdSetPack(int id, char* buffer);
bool SendRoomFullPack(int id);
bool SendPlayerJoinPack(int id, char* buffer);
bool SendPlayerListPack(int id,char* buffer);
bool SendPlayerQuitPack(int id, char* buffer);
bool SendGameStartPack();
bool SendRoomOverPack();
bool BroadcastPlayerPositionUpdatePackToPlayer(int playerId,int tick,int x,int y,int direction,char* buffer);
bool BroadcastPlayerPositionForceUpdatePackToPlayer(int playerId,int tick,int x,int y,int direction,char* buffer);
bool BroadcastProjectileCrashPackToPlayer(int playerId,int tick,int projectileId,char *buffer);
bool BroadcastPlayerAccumulatePowerPackToPlayer(int playerId,int tick,int second,char *buffer);
bool BroadcastProjectileShootPackToPlayer(int playerId,int projectileId,int x,int y,int direction,int level,int tick,char *buffer);
bool BroadcastProjectileDurabilityUpdatePackToPlayer(int playerId,int projectileId,int tick,int durability, char *buffer);
bool BroadcastPlayerAmmunitionUpdatePackToPlayer(int playerId,int tick,int ammunition,char *buffer);
bool BroadcastPlayerHealthUpdatePackToPlayer(int playerId,int tick,int health,char *buffer);
bool BroadcastBlockHealthUpdatePackToPlayer(int playerId,int tick,int col,int row,int health,char *buffer);
bool BroadcastPlayerBaseHealthUpdatePackToPlayer(int playerId,int tick,int health,char *buffer);
bool BroadcastGameOverPackToPlayer(int winnerId,int tick,char *buffer);
bool BroadcastPlayerDisconnectPackToPlayer(int playerId,int tick,char *buffer);
//client
bool SendJoinRequest();
bool SendQuitRequest(int id);
bool SendBackRequest(int id);
bool ResponseGameStartPack();
bool SendPlayerPositionUpdatePackToServer(int id,int x,int y,int direction,int tick);
//bool SendProjectileCrashPackToServer(int playerId,int projectileId,int x,int y,int tick);
bool SendPlayerAccumulatePowerPackToServer(int id,int second,int tick);
bool SendProjectileShootPackToServer(int id,int projectileId,int level,int x,int y,int direction,int tick);
bool SendPlayerAmmunitionUpdatePackToServer(int id,int ammunition,int tick);
#endif //GAME_NETDATA_H
